﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRM.DataAccess.Entities;
using CRM.Business.Services;
using CRM.Encryption;
using Telerik.Web.UI;

namespace Web.EmailTemplate
{
    public partial class AddNewEmailTemplate : System.Web.UI.Page
    {
        static string prevPage = String.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            if (Request.UrlReferrer != null)
            {
                prevPage = Request.UrlReferrer.ToString();
                hdntxtPrevPage.Value = prevPage;
            }
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                EMAIL_TEMPLATE etempl = new EMAIL_TEMPLATE();
                etempl.DESCRIPTION = txtDescription.Text;
                etempl.MESSAGE = txtMessage.Text;
                etempl.SUBJECT = txtSubject.Text;
                etempl.TEMPLATE_NAME = txtTemplateName.Text;
                int re = EmailTemplateService.addNewEmailTemplate(etempl);
                if (re == 1)
                {
                    RadAjaxManager.GetCurrent(this).ResponseScripts.Add(@"ShowMessageAndRedirect('" + "Create new email template successful !" + "','" + "EmailTemplates.aspx" + "');");
                    //MessageBox.Show(this, GetType(), "Create new email template successful !", "EmailTemplates.aspx");
                }
            }
            catch
            {
                RadAjaxManager.GetCurrent(this).ResponseScripts.Add(@"ShowMessage('" + "Can not create email template !" + "');");
                //ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('Can not create email template !');", true);
            }
        }
    }
}